package com.iarc.base.activity

import android.os.Bundle
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import com.iarc.base.viewmodel.BaseViewModel
import java.lang.reflect.ParameterizedType

/**
 * author:kanlulu
 * data  :7/5/21 2:45 PM
 * ViewModel  Activity
 **/
abstract class BaseVmDbActivity<VM : BaseViewModel, DB : ViewDataBinding> :
    BaseActivity<DB>() {
    lateinit var mViewModel: VM

    override fun onCreate(savedInstanceState: Bundle?) {
        mViewModel = createViewModel()

        super.onCreate(savedInstanceState)
    }

    private fun createViewModel(): VM {
        return ViewModelProvider(this).get((this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<VM>)
    }

}